package com.zeyigou.sellergoods.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zeyigou.mapper.TbBrandMapper;
import com.zeyigou.pojo.PageResult;
import com.zeyigou.pojo.TbBrand;
import com.zeyigou.pojo.TbBrandExample;
import com.zeyigou.sellergoods.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by WF on 2020/11/12 16:46
 */
@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private TbBrandMapper brandMapper;
    //1.查询所有品牌
    @Override
    public List<TbBrand> findAll() {
        return brandMapper.selectAll();
    }
    //2.分页查询
    @Override
    public PageResult<TbBrand> findBypage(int page, int pageSize) {
        //2.1)开始分页
        PageHelper.startPage(page,pageSize);
        //2.2)进行实例查询
        TbBrandExample example = new TbBrandExample();
        List<TbBrand> tbBrands = brandMapper.selectByExample(example);
        //2.3)转换为Page<TbBrand>对象
        Page<TbBrand> brandPage = (Page<TbBrand>) tbBrands;
        //2.4)返回PageResult对象
        return new PageResult<>(brandPage.getTotal(),brandPage.getResult());
    }


}
